#include"process.h"
#include<stdio.h>
#include<string.h>
#include<unistd.h>


#define NUM 101
#define STYLE '#'
#define STYLE2 '.' 
#define POINTSNUM 6
#define SPACE ' '

// version 2:真实的进度条，应该根据具体的比如下载的量，来动态刷新进度
void FlushProcess(double current ,double total)
{	

	//1.更新当前进度百分比
	double rate = (current/total)*100;
	//printf("test:%.1lf%%\r",rate);
	//fflush(stdout);
	
	//2.进行图形化界面更新
	char bar[NUM];
	memset(bar,'\0',sizeof(bar));
	int i=0;
	for( ; i< (int)rate ;i++)
	{
		bar[i]=STYLE;	
	}
	
	//3.加载动画的设置
	static int num=0;
	num++;
	num%=POINTSNUM;
 
	char points[POINTSNUM];
	memset(points ,'\0' ,sizeof(points));
	int j=0;
	for( ;j<POINTSNUM ;j++)
	{
	      if(j < num) points[j]= STYLE2;
	      else points[j] = SPACE;	
	}

	printf("[%-100s][%.1lf%%]%s\r" ,bar ,rate , points);
	fflush(stdout);
	
		
}



    //version1
//void process()
//{
//	const char *lable = "|/-\\";
//	int len = strlen(lable);
//	int cnt = 0;
//	char bar[NUM];
//	memset(bar ,'\0', sizeof(bar));
//	while(cnt<=100)
//	{
//		printf("[%-100s][%d%%][%c]\r",bar ,cnt,lable[cnt%len]);
//		fflush(stdout);
//		bar[cnt] = STYLE;
//		cnt++;
//		usleep(100000);
//	}
//	printf("\r\n");
//}
